<?php
	require("../Model/MySQL.php");
	require("../host_config.php");
	session_start();
	error_reporting(E_ALL);
	if (!isset($_SESSION['username'])) {
        echo "<script language='javascript'>";
        echo "alert('You have no permission to read this page!');";
        echo "history.back();";
        echo "</script>";
        header("location:../login.php");
    	}else {

	$mysql = new MySQL();
	$link = $mysql->connect($mysql_host, $mysql_user, $mysql_password, $mysql_db);
	$result = mysql_query("SELECT account FROM user", $link);
	//$result = mysql_query("SELECT account as temp from user union select name as temp from user", $link);
	while ($row = mysql_fetch_assoc($result)) {
   		$colors[]=$row['account'];
	}
	$part = $_GET['part'];
	$part = mysql_real_escape_string($part);
	if(isset($part) and $part != '')
	{
		// initialize the results array
		$results = array();

		// search colors
		foreach($colors as $color)
		{
			// if it starts with 'part' add to results
			if( strpos($color, $_GET['part']) === 0 ){
				$results[] = $color;
			}
		}

		// return the array as json with PHP 5.2
		echo json_encode($results);
	}
	}
?>
